var map;
var map_img = 'map_img';
var div_id;
var lat;
var lng;
var llat;
var llng;
var lat_lng;
var txt;
var p_id = 'map_set';
var pm_id = 'metro_set';
var AdminArea_id = 'AdminArea';
var AdminArea_pos_id = 'AdminArea_pos';
var AdminArea_id_select = 'AdminArea_select';
var Locality_id = 'Locality';
var Locality_pos_id = 'Locality_pos';
var Locality_id_select = 'Locality_select';
var Thoroughfare_id = 'Thoroughfare';
var Thoroughfare_pos_id = 'Thoroughfare_pos';
var Thoroughfare_id_select = 'Thoroughfare_select';
var house_id = 'Premise';
var house_pos_id = 'Premise_pos';
var house_id_select = 'Premise_select';
var current_pos_id = 'current_pos';
var source_id;
var source;
var target;
var list_array;
var incr = 13;
var src;
var r_text = '';
var id_src;
var val_str;

function add_hidden_input(id_src, val_str) {
	if(!document.getElementById(id_src)) {
		var objHTML = document.createElement('INPUT');
		objHTML.type = 'hidden';
		objHTML.name = id_src;
		objHTML.id = objHTML.name;
		objHTML.value = val_str;
		document.getElementById(p_id).appendChild(objHTML);
	} else
		document.getElementById(id_src).value = val_str;
}

/*
 function getCookie(name) {
 var prefix = name + "="
 var cookieStartIndex = document.cookie.indexOf(prefix)
 if (cookieStartIndex == -1)
 return null
 var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
 if (cookieEndIndex == -1)
 cookieEndIndex = document.cookie.length
 return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
 }
 */

function set_visible_map(r_text) {

	if(document.getElementById('showmap').checked == true) {

		if(document.getElementById('current_pos')) {
			document.getElementById('map_show').style.display = '';
			initmap('map_show', document.getElementById('current_pos').value, '', incr, r_text);
		} else
			alert('Чтобы объект отобразился на карте нажмите кнопку Сброс и уточните адрес');

		eventAdder(document.getElementById('showmap'), "onclick", "set_visible_map();");
	} else
		document.getElementById('map_show').style.display = 'none';
}

function reset_searchstr() {

	if(document.getElementById('searched'))
		document.getElementById('searched').value = '';

	do
		document.getElementById(p_id).removeChild(document.getElementById(p_id).lastChild);
	while (document.getElementById(p_id).lastChild);

	document.getElementById('map_show').style.display = 'none';
	var objHTML = document.createElement('INPUT');
	objHTML.type = 'button';
	objHTML.id = 'search_button';
	objHTML.value = 'Выбрать';
	document.getElementById(p_id).appendChild(objHTML);
	eventAdder(document.getElementById(objHTML.id), "onclick", "update_searchstr('AdminArea_select');");
	create_list(obl);
}

function arrayUnique(ar) {
	var a = [];
	var l = ar.length;

	for(var i = 0; i < l; i++) {
		for(var j = i + 1; j < l; j++) {
			if(ar[i] === ar[j])
				j = ++i;
		}
		a.push(ar[i]);
	}
	return a;
}

var ind;
function update_searchstr(source_id, ind) {

	if(source_id == 'AdminArea_select')
		metro_hide();

	if(!document.getElementById('searched')) {
		var objHTML = document.createElement('INPUT');
		objHTML.id = 'searched';
		objHTML.name = 'searched';
		objHTML.type = 'hidden';
		document.getElementById(p_id).appendChild(objHTML);
	}

	if(!ind)
		ind = document.getElementById(source_id).options.selectedIndex;

	if(document.getElementById('searched').value == '')
		document.getElementById('searched').value = document.getElementById(source_id).options[ind].text;
	else {
		var old_text = document.getElementById('searched').value;
		var new_text = document.getElementById(source_id).options[ind].text;
		var updated_text;

		//вместо 'Московкая область' и 'в четре Москвы' -> 'Москва,'
		if(old_text == "населенный пункт в черте Москвы" && new_text.substr(0, 7) == "Москва,")
			old_text = 'Москва';
		if(old_text == "Московская область" && new_text.substr(0, 7) == "Москва,")
			old_text = 'Москва';
		updated_text = old_text + ', ' + new_text;

		if(!document.getElementById('trust_map') && (old_text == 'Москва' || old_text == 'Московская область')) {
			var objHTML = document.createElement('INPUT');
			objHTML.id = 'trust_map';
			objHTML.name = 'trust_map';
			objHTML.type = 'hidden';
			objHTML.value = '1';
			document.getElementById(p_id).appendChild(objHTML);
		}

		//вырезаем повторения в updated_text
		var text_arr = updated_text.split(", ");
		text_arr = arrayUnique(text_arr);
		updated_text = text_arr.join(", ");

		//document.getElementById('searched').value = document.getElementById('searched').value  + ", " + document.getElementById(source_id).options[ind].text;

		document.getElementById('searched').value = updated_text;
	}
	if(document.getElementById('searched_text'))
		document.getElementById(p_id).removeChild(document.getElementById('searched_text'));
	if(!document.getElementById('searched_text')) {
		var objHTML = document.createElement('H4');
		objHTML.id = 'searched_text';
		objHTML.style.color = 'green';
		document.getElementById(p_id).insertBefore(objHTML, document.getElementById(p_id).firstChild);
		var text = document.createTextNode(document.getElementById('searched').value);
		document.getElementById(objHTML.id).appendChild(text);

		$('#searched_text').prepend('<font color=blue><small>выбрано:</small> </font>');

		var objHTML_reset = document.createElement('INPUT');
		objHTML_reset.id = 'reset_button';
		objHTML_reset.type = 'button';
		objHTML_reset.value = '<< Отмена';
		objHTML_reset.title = 'Очистить адрес';
		document.getElementById('searched_text').appendChild(objHTML_reset);
		eventAdder(document.getElementById(objHTML_reset.id), "onclick", "reset_searchstr();");
	}

	if(!document.getElementById('showmap')) {
		var objHTML = document.createElement('INPUT');
		objHTML.id = 'showmap';
		objHTML.type = 'checkbox';
		document.getElementById(p_id).appendChild(objHTML);
		eventAdder(document.getElementById(objHTML.id), "onclick", "set_visible_map();");
		document.getElementById(p_id).appendChild(document.createTextNode('свериться с картой'));

	}

	try {
		document.getElementById(current_pos_id).value = document.getElementById(source_id).options[ind].value;
	} catch(a) {
		var objHTML = document.createElement('INPUT');
		objHTML.type = 'hidden';
		objHTML.id = current_pos_id;
		objHTML.name = current_pos_id;
		document.getElementById(p_id).appendChild(objHTML);
		document.getElementById(current_pos_id).value = document.getElementById(source_id).options[ind].value;
	}

	var objHTML = document.createElement('INPUT');
	objHTML.type = 'text';
	objHTML.style.color = 'red';

	if(source_id === AdminArea_id_select && document.getElementById(source_id).options[ind].text != 'Москва' && document.getElementById(source_id).options[ind].text != 'Санкт-Петербург') {
		objHTML.size = 100;
		objHTML.value = 'впишите название населенного пункта,   а потом нажмите кнопку        Искать >>';
		objHTML.id = Locality_id;
		eventAdder(document.getElementById('search_button'), "onclick", "get_objects(document.getElementById('" + Locality_id + "').value,'" + Locality_id + "','" + Locality_id_select + "');");
	}
	if(source_id === Locality_id_select || ((document.getElementById(source_id).options[ind].text === 'Москва' || document.getElementById(source_id).options[ind].text === 'Санкт-Петербург') && source_id === AdminArea_id_select)) {
		objHTML.size = 100;
		objHTML.value = 'впишите НЕСКОЛЬКО БУКВ из названия улицы,   а потом нажмите кнопку        Искать >>';
		objHTML.id = Thoroughfare_id;
		eventAdder(document.getElementById('search_button'), "onclick", "get_objects(document.getElementById('" + Thoroughfare_id + "').value,'" + Thoroughfare_id + "','" + Thoroughfare_id_select + "');");
	}
	if(source_id === Thoroughfare_id_select) {
		objHTML.size = 100;
		objHTML.value = 'впишите номер дома,   а потом нажмите кнопку        Искать >>';
		objHTML.id = house_id;
		eventAdder(document.getElementById('search_button'), "onclick", "get_objects(document.getElementById('" + house_id + "').value,'" + house_id + "','" + house_id_select + "');");
	}

	if(source_id != house_id_select) {
		eventAdder(objHTML, "onclick", "if(this.style.color!='blue')this.value='';this.style.color='blue';");
		document.getElementById(p_id).insertBefore(objHTML, document.getElementById('search_button'));
		document.getElementById('search_button').value = 'Искать >>';
	}

	var objHTML = document.createElement('INPUT');
	objHTML.type = 'hidden';
	objHTML.name = source_id + '_name';
	objHTML.id = objHTML.name;
	objHTML.value = document.getElementById(source_id).options[ind].text;
	document.getElementById(p_id).appendChild(objHTML);

	document.getElementById(p_id).removeChild(document.getElementById(source_id));

	var objHTML = document.createElement('INPUT');
	objHTML.type = 'hidden';
	objHTML.name = source_id;
	objHTML.value = document.getElementById(current_pos_id).value;
	document.getElementById(p_id).appendChild(objHTML);

	if(source_id === AdminArea_id_select)
		incr = 9;
	if(source_id === Locality_id_select)
		incr = 14;
	if(source_id === Thoroughfare_id_select)
		incr = 15;
	if(source_id === house_id_select)
		incr = 17;
	//подсчитаем расстояния
	var from_metro_text = '';
	//calc_distances();
	//сменим если нужно карту
	if(document.getElementById('showmap').checked == true)
		initmap('map_show', document.getElementById('current_pos').value, '', incr, from_metro_text);
	//опустим чекбокс свриться с картой
	$('#showmap').before("<br>");
}

function getXmlHttp() {
	var request = null;
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			request = false;
		}
	}
	if(!request && typeof XMLHttpRequest != 'undefined') {
		request = new XMLHttpRequest();
	}
	return request;
}

function get_objects(txt, source, target) {
	document.getElementById(p_id).removeChild(document.getElementById('search_button'));
	var objHTML = document.createElement('INPUT');
	objHTML.type = 'image';
	objHTML.id = 'search_button';
	objHTML.src = "/images/progress.gif";
	document.getElementById(p_id).insertBefore(objHTML, document.getElementById('showmap'));

	var llspn = "";
	var ll = "";
	var spn = "";
	var currpos = "";
	if(document.getElementById('current_pos')) {
		var current = document.getElementById('current_pos').value;
		var coords = current.split(' ');

		var results = 30;
		if(source == 'Thoroughfare' || source == 'Premise')
			results = 1;

		if(coords[2] && coords[3] && coords[4] && coords[5]) {
			var llspn = "&results=" + results + "&ll=" + (((coords[4] * 1) + (coords[2] * 1)) / 2).toFixed(6) + "," + (((coords[5] * 1) + (coords[3] * 1)) / 2).toFixed(6) + "&spn=" + (coords[4] - coords[2]).toFixed(6) + "," + (coords[5] - coords[3]).toFixed(6) + "&rspn=0";
		}
		if(coords[0] && coords[1]) {
			var curpos = coords[0] + "-" + coords[1];
		}
	}
	document.getElementById(p_id).removeChild(document.getElementById(source));
	var url = "/js/map.php";
	var geocode = 'Россия, ' + document.getElementById('searched').value + ', ';
	var text2 = txt;
// 	&results=1&ll=37.609218,55.752655&spn=0.833332,0.530138&rspn=0
//37.609217 55.753558 34.781753 54.001680 40.781834 57.268665
	var request = getXmlHttp();
	request.open("POST", url, true);
	request.onreadystatechange = function() {
		if(request.readyState == 4) {
			if(request.status == 200) {
				var ds = request.responseText.replace(/\n/, '');
				var res = create_list(ds);
				if(!res) {
					var objHTML = document.createElement('INPUT');
					objHTML.type = 'text';
					objHTML.size = 100;
					eventAdder(objHTML, "onclick", "if(this.style.color!='blue')this.value=''; this.style.color='blue';");
					objHTML.id = ds;
					objHTML.style.color = 'red';
					document.getElementById(p_id).insertBefore(objHTML, document.getElementById('search_button'));
					if(ds == 'Thoroughfare')
						document.getElementById(ds).value = 'не найдено, попробуйте вписать ПОЛНОЕ название улицы';
					else
						document.getElementById(ds).value = 'не найдено, попробуйте еще сверясь с картой...';

					document.getElementById(p_id).removeChild(document.getElementById('search_button'));
					var objHTML = document.createElement('INPUT');
					objHTML.type = 'button';
					objHTML.id = 'search_button';
					objHTML.value = 'Искать >>';
					document.getElementById(p_id).insertBefore(objHTML, document.getElementById('showmap'));

					eventAdder(document.getElementById('search_button'), "onclick", "alert('Найти');");
					eventAdder(document.getElementById('search_button'), "onclick", "get_objects(document.getElementById('" + ds + "').value,'" + ds + "','" + ds + "_select');");
				}
			} else {
				var message = request.getResponseHeader("Status");
				if((message == null) || (message.length <= 0)) {
					alert("Please waiting, request status is " + request.status);
				} else {
					alert(message);
				}
			}
		}

	};

	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.send("target=" + escape(target) + "&text=" + geocode + "&text2=" + text2 + "&id_source=" + escape(source) + "&curpos=" + curpos + "&llspn=" + escape(llspn));
	if(document.getElementById('xml_link'))
		document.getElementById('xml_link').href = "http://geocode-maps.yandex.ru/1.x/?geocode=" + geocode + text2 + llspn + "&key=AM0HHkkBAAAAwpaMAAMAGxTKK4ak-Op3Yn4vq0_6dwmt_8UAAAAAAAAAAAAmv0moL0kNvPE1vxbM7xTlvz8HEA==" + "&currpos=" + currpos;
}

var default_selected;

function metro_hide() {

	var show_metro_set;
	var metros_options = '';

	if($("#AdminArea_select option:selected").val() == "37.609218 55.753559 37.192552 55.487586 38.025884 56.017724" || $("#AdminArea_select option:selected").val() == "37.609217 55.753558 34.781753 54.001680 40.781834 57.268665" || $("#AdminArea_select option:selected").val() == "37.781793 55.669397 34.781753 54.001680 40.781834 57.268665") {
		show_metro_set = 1;
		metros_options = '';
		for(var i = 0; i < metro_stations_array.length; i++) {
			if(metro_stations_array[i].k < 255) {
				metros_options = metros_options + '<option value=' + metro_stations_array[i].k + '>' + metro_stations_array[i].v + '</option>';
			}
		}

	}

	if($("#AdminArea_select option:selected").val() == "30.313497 59.938531 29.646749 59.631268 30.980244 60.242964")// || $("#AdminArea_select option:selected").val() == "31.273643 59.906021 26.580233 58.417072 35.967053 61.330865" )
	{
		show_metro_set = 1;
		metros_options = '';
		for(var i = 0; i < metro_stations_10_array.length; i++) {
			metros_options = metros_options + '<option value=' + metro_stations_10_array[i].k + '>' + metro_stations_10_array[i].v + '</option>';
		}

	}

	if(metros_options != '') {
		var insert_html = "<fieldset style='display: inline; padding: 5px;'><legend>" + "<b>до Метро</b></legend>минут: <input id='min_user' name='min' size='2' value=''> <input id='goby1_user' name='goby' value='0' checked='checked' type='radio'> пешком <input id='goby2_user' name='goby' value='1' type='radio'> на автомобиле <br>от ст.метро " + "<select id='id_metro' name='id_metro'><option value='0'>&nbsp;</option>" + metros_options + "</select></fieldset>";

		$("#metro_set").hide();
		$("#metro_set").empty();
		$("#metro_set").html(insert_html);
		$("#metro_set").show();
	} else {
		$("#metro_set").hide();
	}
}

function create_list(list_array, default_selected) {

	try {
		var causes_array = eval(list_array);
	} catch(a) {
	}

	if(causes_array) {
		//очистим от списков сделанных до этого
		if(list_array == obl)
			$("#map_set").empty();
		var selectElement = document.createElement("select");
		for(var i = 0; i < causes_array.length; i++) {
			if(default_selected > 0 && i == default_selected)
				def_selected = true;
			else
				def_selected = false;
			selectElement.options[i] = new Option(causes_array[i].v, causes_array[i].k + ' ' + causes_array[i].bl + ' ' + causes_array[i].bu, false, def_selected);
			selectElement.id = causes_array[i].n;
		}
		selectElement.name = selectElement.id;

		if(document.getElementById('search_button'))
			document.getElementById(p_id).removeChild(document.getElementById('search_button'));
		var objHTML = document.createElement('INPUT');
		objHTML.type = 'button';
		objHTML.id = 'search_button';
		objHTML.value = 'Выбрать';
		document.getElementById(p_id).insertBefore(objHTML, document.getElementById('showmap'));
		eventAdder(document.getElementById('search_button'), "onclick", "update_searchstr('" + selectElement.id + "');");
		document.getElementById(p_id).insertBefore(selectElement, document.getElementById('search_button'));
		if(list_array == obl)
			eventAdder(document.getElementById('AdminArea_select'), "onchange", "metro_hide();");

		if(causes_array.length === 1) {
			update_searchstr(selectElement.id);
			if(selectElement.id === house_id_select) {
				document.getElementById(p_id).removeChild(document.getElementById('search_button'));
			}
		}

		return true;
	} else
		return false;
}

function eventAdder(objAttrib, handler, addFunction) {

	if((!document.all) && (document.getElementById)) {
		objAttrib.setAttribute(handler, addFunction);
	}
	if((document.all) && (document.getElementById)) {
		objAttrib[handler] = new Function(addFunction);
	}
}

function initmap(div_id, lat_lng, txt, incr, r_text) {
	YMaps.load(function() {
		initmaps(div_id, lat_lng, txt, incr, r_text)
	});
}

function initmaps(div_id, lat_lng, txt, incr, r_text) {
	if(txt == '')
		txt = 'текущая позиция';
	map = new YMaps.Map(document.getElementById(div_id));
	map.addControl(new YMaps.TypeControl());
	map.addControl(new YMaps.Zoom());
	map.addControl(new YMaps.ScaleLine());
	lat_lng = lat_lng.split(' ');
	lat = lat_lng[0];
	lng = lat_lng[1];

	document.getElementById(div_id).style.display = '';
	var point = new YMaps.GeoPoint(lat, lng);
	map.setCenter(point, incr);
	var placemark = new YMaps.Placemark(point);

	if(document.getElementById('metro_point')) {
		var metro_txt = "До&nbsp;<a href=\"javascript: map.panTo(new YMaps.GeoPoint(" + document.getElementById('metro_point').value + "));\">метро</a><br>";
		var distance_txt;
		if(document.getElementById('dist_map'))
			distance_txt = "пешком&nbsp;по&nbsp;прямой&nbsp;" + "&nbsp;&asymp;&nbsp;" + document.getElementById('min_map').value + "мин&nbsp;(" + YMaps.humanDistance(document.getElementById('dist_map').value) + ")";
		if(document.getElementById('dist2_map'))
			distance_txt = distance_txt + '<br>транспортом без пробок &asymp; ' + document.getElementById('min2_map').value + 'мин (' + YMaps.humanDistance(document.getElementById('dist2_map').value) + ')';

		if(distance_txt)
			r_text = metro_txt + distance_txt;
		if(r_text)
			placemark.setBalloonContent(r_text);
	}
	map.addOverlay(placemark);
	if(r_text)
		placemark.openBalloon();
}

function createmap(div_id, lat_lng) {
	lat_lng = lat_lng.split(' ');
	lat = lat_lng[0];
	lng = lat_lng[1];
	llat = lat_lng[4] - lat_lng[2];
	llng = lat_lng[5] - lat_lng[3];
	if(!document.getElementById(map_img))
		var objHTML = document.createElement('IMG');
	else
		var objHTML = document.getElementById(map_img);
	objHTML.src = "http://static-maps.yandex.ru/1.x/?ll=" + lat + "," + lng + "&pt=" + lat + "," + lng + ",pmlbs&spn=" + llat + "," + llng + "&l=map&key=AM0HHkkBAAAAwpaMAAMAGxTKK4ak-Op3Yn4vq0_6dwmt_8UAAAAAAAAAAAAmv0moL0kNvPE1vxbM7xTlvz8HEA==";
	objHTML.id = map_img;
	document.getElementById(div_id).appendChild(objHTML);
}

function edit_form_submit() {
	calc_distances();
	$("#edit_form_submit_button").before("<br><img src='/images/progress.gif'> сохраняем...<br><br>");
	$("#edit_form_submit_button").remove();
	setTimeout("$('#object_edit_form').submit();", 1700);
	//$('#object_edit_form').submit();
}

function calc_distances() {

	//если выбрано метро и номер дома, то ищем расстояния
	//if(document.getElementById('id_metro') && document.getElementById('id_metro').options.selectedIndex>0  && (document.getElementById('Premise_select_name') || document.getElementById('house')) && document.getElementById('current_pos'))
	if(document.getElementById('id_metro') && document.getElementById('id_metro').options.selectedIndex > 0 && document.getElementById('trust_map') && document.getElementById('current_pos')) {
		lat_lng = document.getElementById('current_pos').value;
		lat_lng = lat_lng.split(' ');
		lat = lat_lng[0];
		lng = lat_lng[1];

		if(!point)
			var point = new YMaps.GeoPoint(lat, lng);

		var metro_value = document.getElementById('id_metro').options.selectedIndex
		var metro_name = document.getElementById('id_metro').options[metro_value].text;
		metro_name = 'Россия, Москва, станция метро ' + metro_name;

		//alert(metro_value);

		if(metro_stations && metro_value) {
			metro_pos = metro_stations_array[(metro_value - 1)].pos;
			//alert(metro_pos);
			//alert(metro_stations_array[(metro_value-1)].v);
			metro_pos = metro_pos.split(' ');
			metro_name = new YMaps.GeoPoint(metro_pos[0], metro_pos[1]);
			//alert(metro_name);
		}

		// маршрут на транспорте
		var router = new YMaps.Router([metro_name, point], [1], {
			viewAutoApply : false
		});
		YMaps.Events.observe(router, router.Events.Success, function() {
			var fullDistance = router.getDistance().toFixed(0);
			var fullTime = (router.getDuration() / 60).toFixed(0);
			add_hidden_input('dist2_map', fullDistance);
			add_hidden_input('min2_map', fullTime);
			set_distance();
		});

		// по прямой
		var metro_point = metro_name;
		var fullDistance = point.distance(metro_point).toFixed(0);
		var fullTime = (fullDistance / (6000 / 60)).toFixed(0);
		add_hidden_input('dist_map', fullDistance);
		add_hidden_input('min_map', fullTime);
		add_hidden_input('metro_point', metro_point);
		// выставляем вычисленное расстояние, если этого хотел пользователь
		set_distance();

		/*
		 // по прямой
		 //var geocoder = new YMaps.Geocoder(metro_name, {results: 1, boundedBy: map.getBounds()});
		 var geocoder = new YMaps.Geocoder(metro_name, {results: 1});
		 YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
		 if (this.length()) {
		 geoResult = this.get(0);
		 var metro_point = geoResult.getGeoPoint();
		 var fullDistance = point.distance(metro_point).toFixed(0);
		 var fullTime = (fullDistance/(6000/60)).toFixed(0);
		 add_hidden_input('dist_map',fullDistance);
		 add_hidden_input('min_map',fullTime);
		 add_hidden_input('metro_point',metro_point);
		 // выставляем вычисленное расстояние, если этого хотел пользователь
		 set_distance();
		 }
		 });
		 */
	}
}

function set_distance() {
	if(document.getElementById('goby1_user') && document.getElementById('goby2_user') && document.getElementById('trust_map') && document.getElementById('min_user') && document.getElementById('dist_map') && document.getElementById('dist2_map') && document.getElementById('min_map') && document.getElementById('min2_map')) {
		var dist_map = document.getElementById('dist_map').value;
		var dist2_map = document.getElementById('dist2_map').value;
		var min_map = document.getElementById('min_map').value;
		if(min_map == 0)
			min_map = 1;
		var min2_map = document.getElementById('min2_map').value;
		if(min2_map == 0)
			min2_map = 1;
		if(min_map > 15)
			var goby_map = 2;
		if(min_map > 0 && min_map < 16)
			var goby_map = 1;
		//if(document.getElementById('trust_map').checked)
		// {
		//	document.cookie = "trust_map=true; expires=Wed, 16 Mar 2016 00:00:00";
		if(goby_map == 1) {
			document.getElementById('min_user').value = min_map;
			document.getElementById('goby1_user').checked = true;
			document.getElementById('goby2_user').checked = false;
		}
		if(goby_map == 2) {
			document.getElementById('min_user').value = min2_map;
			document.getElementById('goby2_user').checked = true;
			document.getElementById('goby1_user').checked = false;
		}
		// }
	}
}

